require "mysql"
puts "Monitor is running"
loop do
	$mysqlstat = `service mysql status`
	begin
	dbh = Mysql.real_connect('192.168.3.240','root','','UniqueMgr_development')
	dbh.query("UPDATE main SET status='#{$mysqlstat}' WHERE ip='240' AND services='mysql'")
	cmd = dbh.query("SELECT action FROM main WHERE ip='240' AND services='mysql' ")
	dbh.query("UPDATE main SET action='0' WHERE ip='240' AND services='mysql'")
	ensure
	dbh.close if dbh
	end
	if cmd==1 then
		system('service mysql restart')
	end
	sleep 1
end